<?php

$serv = new swoole_server("0.0.0.0", 80);

// $port->on('packet', function($serv, $data, $client) {
// 	var_dump($data, $client);
// 	$serv->sendto($client['address'], $client['port'], "welcome admin\n");
// });

$serv->on('start', function($serv) {  
    echo 'start',PHP_EOL;  
}); 

$serv->on('WorkerStart', function ($serv, $worker_id){ 
    //global $argv; 
    if($worker_id >= $serv->setting['worker_num']) { 
        swoole_set_process_name("php task worker"); 
    } else { 
        swoole_set_process_name("php event worker"); 
    } 
}); 


$serv->on('WorkerStop', function ($serv, $worker_id){  
    echo "on WorkerStop\n"; 
}); 

$serv->on('connect', function ($serv, $fd) {
    echo "Client:Connect.\n";
});

$serv->on('receive', function (swoole_server $serv, $fd, $from_id, $data) {
    //$info = $serv->connection_info($fd, $from_id);
    //var_dump($info);
	//$serv->send($fd, 'Swoole: '.$data);
	var_dump($data);

	$client = new swoole_client(SWOOLE_SOCK_TCP);

	if(!$client->connect('192.168.99.100', 22, -1)){
		$client->send($data);
	}
});

$serv->on('close', function ($serv, $fd) {
    echo "Client: Close.\n";
});
$serv->start();